﻿using McMaster.Extensions.CommandLineUtils;

namespace Batman.CommandLine
{
    public abstract class CommandLineApplicationBase
    {
        protected CommandLineApplication _CommandLineApplication { get; set; }

        public abstract string Name { get; }

        public abstract string Description { get; }

        public CommandLineApplicationBase()
        {
            _CommandLineApplication = new CommandLineApplication(false)
            {
                Name = Name,
                Description = Description
            };

            _CommandLineApplication.HelpOption("-h|--help");
        }

        public abstract void OnExecute();

        public virtual void Execute(string[] args)
        {
            _CommandLineApplication.OnExecute(() =>
            {
                this.OnExecute();
                return 1;
            });
            _CommandLineApplication.Execute(args);
        }
    }
}
